import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;

public class work2 {
    public  static int lengthOfLongestSubstring(String s) {
        HashSet<Character> set=new HashSet<>();
        int ret=0;
        int left=0;
        int right=0;
        while (right<s.length()){
            while(!set.contains(s.charAt(right))){
                set.add(s.charAt(right));
                right++;
            }
            while (left<=right&&s.charAt(left)!=s.charAt(right)){
                set.remove(s.charAt(left));
                left++;
            }
            set.remove(left);
            left++;
            ret=Math.max(ret,right-left+1);
            right++;
        }
        return ret;
    }

    public static void main(String[] args) {
        String s= "bbbbb";
        System.out.println(lengthOfLongestSubstring(s));

    }
}
